package Solutions

func hIndex(citations []int) int {
	dif := make([]int, 1001)
	for i := 0; i < len(citations); i++ {
		dif[citations[i]] += 1
	}
	for i := 999; i >= 0; i-- {
		dif[i] += dif[i+1]
	}
	ans := 0
	for i := 0; i < 1000; i++ {
		if dif[i] < i {
			break
		}
		if ans < dif[i] {
			ans = i
		}
	}
	return ans
}
